import cookie from 'component-cookie';
import _ from 'underscore';
import CONSTANT from '../constant/common';

const set = (data) => {
  cookie(data[0], null);
  cookie(data[0], data[1], _.assign({}, {
    maxage: CONSTANT.COOKIE_DEFAULT_MAXAGE,
    path: CONSTANT.COOKIE_DEFAULT_PATH,
    domain: CONSTANT.COOKIE_DEFAULT_DOMAIN,
  }, data[2]));
};

// option[0] => key
// option[1] => value
// option[2] => data
export default (...option) => {
  switch (option.length) {
    // set cookie
    case 3:
    case 2:
      return set(option);
    // get cookie
    case 1:
      return cookie(option[0]);
    default:
      return cookie();
  }
};
